const app = getApp();

App({
  onLaunch: function () {
    if (wx.cloud) {
      wx.cloud.init({
        traceUser: true
      })
    }
    wx.getSystemInfo({
      success: e => {
        // 顶部状态
        this.globalData.StatusBar = e.statusBarHeight;
        // 胶囊按钮信息
        let custom = wx.getMenuButtonBoundingClientRect();
        // 自定义顶部
        this.globalData.Custom = custom;
        this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
        // 设备可视高宽
        this.globalData.windowHeight = e.windowHeight;
        this.globalData.windowWidth = e.windowWidth;
      }
    })
  },
  globalData: {
   
  }
})

import bData from '../../service/mock.js'
Page({
  data: {
    contentHeight: app.globalData.windowHeight,
    TabCur: null,
    themes: [],
    items: [],
    pigeSize: 6,
    pageNum: 1
  },
  
  onLoad: function (options) {
    var that = this;
    
    var i = bData.getData(this.data.pageNum);
    this.setData({ TabCur: i.themes[0].id, themes: i.themes, items: i.items });

    this._doRefreshMasonry(this.data.items)
  },

  
  onReachBottom: function () {
    var pageNo = this.data.pageNum + 1;
    var data = bData.getData(pageNo, this.data.TabCur);
    if (data.items && data.items.length > 0 ) {
      this.setData({
        pageNum: pageNo
      })
      this._doAppendMasonry(data.items)
    } 
  },

  _doRefreshMasonry(items) {
    this.masonryListComponent = this.selectComponent('#masonry');
    if (this.masonryListComponent) {
      this.masonryListComponent.start(items).then(() => {
      })
    }
  },

  _doAppendMasonry(items) {
    this.masonryListComponent = this.selectComponent('#masonry')
    this.masonryListComponent.append(items).then(() => {
    })
  },

  tabSelect(e) {
    var id = e.currentTarget.dataset.id;
    var data = bData.getData(1, id);
    this.setData({
      TabCur: id,
      items: data.items,
      pageNum:1
    })

    this._doRefreshMasonry([])
    this._doRefreshMasonry(this.data.items);
  }
})
 